package io.renren.modules.app.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.app.entity.NewsThumbEntity;
import io.renren.modules.app.service.NewsThumbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

@RestController
@RequestMapping({"app/newsthumb"})
public class NewsThumbController
{

  @Autowired
  private NewsThumbService newsThumbService;

  @RequestMapping({"/list"})
  public R list(@RequestParam Map<String, Object> params)
  {
    PageUtils page = this.newsThumbService.queryPage(params);

    return R.ok().put("page", page);
  }

  @RequestMapping({"/info/{thumbId}"})
  public R info(@PathVariable("thumbId") Integer thumbId)
  {
    NewsThumbEntity newsThumb = (NewsThumbEntity)this.newsThumbService.getById(thumbId);

    return R.ok().put("newsThumb", newsThumb);
  }

  @RequestMapping({"/save"})
  public R save(@RequestBody NewsThumbEntity newsThumb)
  {
    this.newsThumbService.save(newsThumb);

    return R.ok();
  }

  @RequestMapping({"/update"})
  public R update(@RequestBody NewsThumbEntity newsThumb)
  {
    this.newsThumbService.updateById(newsThumb);

    return R.ok();
  }

  @RequestMapping({"/delete"})
  public R delete(@RequestBody Integer[] thumbIds)
  {
    this.newsThumbService.removeByIds(Arrays.asList(thumbIds));

    return R.ok();
  }
}